from django.db import models

# Create your models here.
from crm.models import User


class Employee(User):
    """
    员工表
    """
    name = models.CharField(max_length=32, unique=True, null=True, verbose_name="姓名")
    birthday = models.DateField(verbose_name='生日', blank=True, null=True)
    age = models.IntegerField(verbose_name='年龄', blank=True, null=True)
    gender = models.CharField(max_length=10, choices=(('Female', '女'), ('Male', '男')), verbose_name='性别',
                              default='Male')
    image = models.ImageField(upload_to='images/%Y/%m', verbose_name='头像', null=True, blank=True)
    depart = models.ForeignKey("Department", on_delete=models.CASCADE, null=True, blank=True)

    USERNAME_FIELD = "username"

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '员工表'
        verbose_name_plural = '员工表'
        ordering = ['date_joined']


class Department(models.Model):
    """
    部门表
    """
    name = models.CharField(max_length=32)
    campuses = models.ForeignKey("Company", on_delete=models.CASCADE, null=True)

    class Meta:
        verbose_name = '部门'
        verbose_name_plural = '部门'

    def __str__(self):
        return self.name


class Company(models.Model):
    """
    公司表
    """
    name = models.CharField(verbose_name='校区', max_length=64)
    address = models.CharField(verbose_name='详细地址', max_length=512, blank=True, null=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '公司表'
        verbose_name_plural = '公司表'


